package com.touchfired.common.http.response;

import com.touchfired.common.exception.ErrorCode;

/**
 * 数据信息处理工具类
 */
@SuppressWarnings("ALL")
public class MsgUtil {

    public static <D> Msg<D> success(D data){
        return success(ErrorCode.SUCCESS, data);
    }

    public static <D> Msg<D> success(ErrorCode errorCode, D data){
        return success(errorCode.getCode(), errorCode.getDesc(), data);
    }

    public static <D> Msg<D> success(int code, String message, D data){
        Msg msg = new Msg();
        msg.setCode(code);
        msg.setMsg(message);
        msg.setData(data);
        msg.setSuccess(true);
        return msg;
    }

    public static <D> Msg<D> error(int code, String message, D data) {
        Msg msg = new Msg();
        msg.setCode(code);
        msg.setMsg(message);
        msg.setData(data);
        msg.setSuccess(false);
        return msg;
    }
}
